#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int N=6e6+5;
int n,m,C,sx,sy,tx,ty;
deque<pair<int,int>>Q;
#define fi first
#define se second
inline int id(int a,int b){return (a-1)*m+b;}
struct Node{int dis,rest;}dis[N];
int mp[N];
char opt;
inline bool cmp(Node a,Node b){
	if(a.dis!=b.dis) return a.dis<b.dis;
	else return a.rest>b.rest;
}
inline Node dec1(Node a){
	if(a.rest) return {a.dis,a.rest-1};
	else return {a.dis+1,C-1};
}
inline Node dec2(Node a){
	if(a.rest) return {a.dis,a.rest-1};
	else return {a.dis,0};	
}
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
signed main(){
	freopen("stamp.in","r",stdin);
	freopen("stamp.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>C>>sx>>sy>>tx>>ty;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			cin>>opt,mp[id(i,j)]=opt=='.',dis[id(i,j)]={0x3f3f3f3f,0};
	dis[id(sx,sy)]={0,0},Q.push_back({sx,sy});
	while(Q.size()){
		pair<int,int>t=Q.front();Q.pop_front();
		int now=id(t.fi,t.se);
		for(int i=0;i<(dis[now].rest==0?4:8);++i){
			int x=t.fi+dx[i],y=t.se+dy[i];
			if(x<1||y<1||x>n||y>m) continue;
			if(mp[id(x,y)]){
				if(!cmp(dec2(dis[now]),dis[id(x,y)])) continue;
				if(!dis[now].rest) Q.push_front({x,y});
				else Q.push_back({x,y});
				dis[id(x,y)]=dec2(dis[now]);
			}
			else if(cmp(dec1(dis[now]),dis[id(x,y)])) Q.push_back({x,y}),dis[id(x,y)]=dec1(dis[now]);	
		}
	}
	cout<<dis[id(tx,ty)].dis<<"\n";
}